package codetest;

import java.io.*;

/**
 * @program: netty
 * @description:
 * @author: 胡海龙
 * @create: 2021-04-14 22:49:19
 **/
public class UserInfoTest {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        UserInfo userInfo = new UserInfo();
        userInfo.buildUserId(100).buildUsername("huhailong");
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutputStream os = new ObjectOutputStream(bos);
        os.writeObject(userInfo);
        os.flush();
        os.close();
        ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray()));
        UserInfo info = (UserInfo)in.readObject();
        System.out.println("read info "+info.getUsername()+info.getUserId());
        byte[]b = bos.toByteArray();
        System.out.println("The jdk serializable length is :"+b.length);
        bos.close();
        System.out.println(userInfo.codeC().length);
        byte[] bytes = userInfo.codeC();
        ObjectInputStream in2 = new ObjectInputStream(new ByteArrayInputStream(bytes));
        UserInfo info2 = (UserInfo)in2.readObject();
        System.out.println("read info2 "+info2.getUsername()+info2.getUserId());
    }
}
